<?php

namespace App\Http\Controllers\Web;

use Illuminate\Http\Request;
use App\Http\Controllers\Web\BaseController;
use App\Http\Model\Admin;

class AdminController extends BaseController
{
    /**
     * 用户登录
     * @param Request $request
     * @return void
     */
    public function login(Request $request)
    {
        $admin_name = trim($request->input('username', ''));
        $admin_pwd = trim($request->input('password', ''));

        if (!$admin_name || !$admin_pwd) {
            return parent::fail('参数有误');
        }

        $admin_info = Admin::where(['admin_name' => $admin_name, 'password' => $admin_pwd])->first();
        if (!isset($admin_info->id)) {
            return parent::fail('数据有误');
        }

        return parent::success($admin_info);
    }
}
